package com.jf.identity.controller;

import com.jf.identity.entity.*;
import com.jf.identity.service.VerifyInfoService;
import com.jf.identity.util.Params;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author FCG
 */
@RequestMapping("vis")
@RestController
public class VerifyInfoController {

    @Resource
    private VerifyInfoService verifyInfoService;

    @RequestMapping("set-identity-validateinfo")
    public ResponseBean setValidateInfo(@Validated @RequestBody VerifyInfoFeedBack verifyInfoFeedBack,
                                        BindingResult bindingResult) {
        Params.beanValidate(bindingResult);
        return new ResponseBean(verifyInfoService.insertVerifyInfo(verifyInfoFeedBack));
    }

    @RequestMapping("set-identity-validate-trailinfo")
    public ResponseBean setTrailInfo( @RequestBody VerifyAbnormalFeedBack verifyAbnormalFeedBack) {
       // Params.beanValidate(bindingResult);
        List<VerifyAbnormalInfo> infos
                = Params.isBlank(verifyAbnormalFeedBack.getValidateInfo(), "验证特征信息");
        for (VerifyAbnormalInfo v: infos) {
            if (v == null) {
                continue;
            }
//            Params.isAnyBlank(v.getSFZJLXM(), v.getSFZJH(), v.getKSH(),
//                    v.getYZSJ(),v.getTZLX(),v.getYZSB(),v.getSBCSDM());
            Params.isNotEmpty(v.getSFZJLXM(),"身份证件类型码");
            Params.isNotEmpty(v.getSFZJH(),"身份证件号");
            Params.isNotEmpty(v.getKSH(),"考试号/考号");
            Params.isNotEmpty(v.getYZSJ(),"验证时间");
            Params.isNotEmpty(v.getTZLX(),"特征类型");
            Params.isNotEmpty(v.getYZSB(),"验证设备编号");
            Params.isNotEmpty(v.getSBCSDM(),"厂商代码");
            if(!"1".equals(v.getTZLX()) && !"2".equals(v.getTZLX())){
                throw new IllegalArgumentException("特征类型，1：证件照片  2:现场采集照片");
            }
        }
        return new ResponseBean(verifyInfoService.insertVerifyAbnormalInfo(infos));
    }

}














